﻿<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>锐浪HTML5报表演示 - <%=request.getParameter("report")%></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="../grhtml5-6.5-min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function window_onload() {
			var reportURL = "<%=request.getParameter("report")%>",
				dataURL = "<%=request.getParameter("data")%>",
                reportViewer;

			if (reportURL == "null") {
				reportURL = "";
			}
			else if (reportURL != "") {
				reportURL = "../../grf/" + reportURL + ".grf";
			}

			if (dataURL == "null") {
				dataURL = "";
			}
			else if (dataURL != "") {
                dataURL = "../../data/DataCenter.jsp?data=" + dataURL;

				//将其它额外的参数也组合到 dataURL
				<%
					java.util.Enumeration Keys = request.getParameterNames();  
					while (Keys.hasMoreElements()) {  
						String key = (String)Keys.nextElement();  
						
						if (!key.equals("report") && !key.equals("data")) {
				%>
							dataURL += "&<%=key%>=" + encodeURIComponent("<%=request.getParameter(key)%>");
				<%
						}
					}
				%>
            }

            //创建报表显示器，参数指定其在网页中的占位标签的ID，关联的报表模板URL，关联的报表数据URL
            reportViewer = window.rubylong.grhtml5.insertReportViewer("report_holder", reportURL, dataURL);

            if (dataURL == "") {
                //如果没有指定报表数据参数，则要从报表模板中设置的查询SQL中获取报表数据
                //此项任务只能在 onReportLoaded 事件中处理
                reportViewer.events.onReportLoaded = onReportLoaded;
            }

            reportViewer.start(); //启动报表运行，生成报表
        }

        function onReportLoaded(viewer) {
            var report = viewer.report,
                masterSQL = report.QuerySQL,
                detailSQL = report.DetailGrid ? report.DetailGrid.Recordset.QuerySQL : "",
                url = "../../data/SQLParam.jsp?QuerySQL=";

            if (!masterSQL && detailSQL) {
                masterSQL = detailSQL;
                detailSQL = "";
            }
            if (masterSQL) {
                url += encodeURIComponent(masterSQL)
                if (detailSQL) {
                    url += "&QuerySQL2=" + encodeURIComponent(detailSQL);
                }

                window.rubylong.ajax(url, function (xmlhttp, success) {
                    this.loadData(xmlhttp, success, 1);
                }, viewer);

                viewer.waitData = true; //阻止在报表模板定义后直接生成报表
            }
        };
    </script>
</head>
<body onload="window_onload()">
    <div id="report_holder"></div>
</body>
</html>